﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using Antu.WebControls;
using Antu.Core.Components;
using Antu.Core.Services;
using System.Web.UI.WebControls;
using EluZSProvider;
using System.Web;
using System.Data;

namespace WebSys.UI.Control.ZhengShou
{
    public class paramsControl : MPBasicTemplate
    {
        EluZSDataProvider _EluZSDataProvider = (EluZSDataProvider)ProviderService.ProviderServiceMange.GetProvider("EluZSProvider");
        public string userid = string.Empty;
        int currentPage = 1, pageSize = 10;
        DropDownList sysparamtypelist;
        protected override void OnLoad(EventArgs e)
        {
            if (HttpContext.Current.Session["UserID"] == null)
            {
                Antu.Utilities.UtilitiesPage.AlertDialogClear("登录超时，请重新登录！", "window.parent.location.href('../login.aspx');");
            }
            else
            {
                userid = HttpContext.Current.Session["UserID"].ToString();
            }
            base.OnLoad(e);
            sysparamtypelist = (DropDownList)FindControl("sysparamtypelist");
            if (base.Page.Request["page"] != null)
            {
                currentPage = Convert.ToInt32(base.Page.Request["page"]);
            }
            if (!base.Page.IsPostBack)
            {
                DataTable dt = _EluZSDataProvider.GetDisParams();
                for (int temp = 0; temp < dt.Rows.Count; temp++)
                {
                    ListItem item = new ListItem(dt.Rows[temp]["name"].ToString(), dt.Rows[temp]["name"].ToString());
                    sysparamtypelist.Items.Add(item);
                }
                if (base.Page.Request["typename"] != null)
                {
                    sysparamtypelist.SelectedValue = base.Page.Request["typename"];
                }
                Bind();
            }
            sysparamtypelist.SelectedIndexChanged += new EventHandler(sysparamtypelist_SelectedIndexChanged);
        }
        protected void Bind()
        {
            MPRepeater MPRepeaterList = (MPRepeater)FindControl("MPRepeaterList");
            Label pagestr = (Label)FindControl("pagestr");
            string strype = base.Page.Request["typename"];
            if (!string.IsNullOrEmpty(strype))
            {
                strype = "and name='" + strype.Trim() + "'";
            }
            else
            {
                strype = "";
            }
            string sql = MPRepeater.OraPageListSql(currentPage, pageSize, "t.*", "zs_params", "id", strype, "trim(name) desc,addtime");

            DataTable dt = _EluZSDataProvider.GetDTTable(sql);
            MPRepeaterList.DataSource = dt;
            MPRepeaterList.DataBind();

            sql = MPRepeater.OraPageListSql("zs_params", "id", strype);
            MPRepeaterList.PageCount = Convert.ToInt32(_EluZSDataProvider.GetDTColumn(sql));
            MPRepeaterList.PageSize = pageSize;
            MPRepeaterList.PageIndex = currentPage;
            MPRepeaterList.PageUrl = "?page={0}" + "&typename=" + base.Page.Request["typename"];
            pagestr.Text = MPRepeaterList.GetPageList();
        }
        protected void sysparamtypelist_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (sysparamtypelist.SelectedValue == "全部")
            {
                base.Page.Response.Redirect("params.aspx");
            }
            else
            {
                base.Page.Response.Redirect("params.aspx?typename=" + sysparamtypelist.SelectedValue);
            }
        }
        protected void MPRepeaterList_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            Label showdel = (Label)e.Item.FindControl("showdel");
            if (_EluZSDataProvider.IsQZSBM(userid) || _EluZSDataProvider.IsSZSB(userid)
                || _EluZSDataProvider.IsZSAdmin(userid) || _EluZSDataProvider.IsNetZSAdmin(userid))
            {
                showdel.Visible = true;
            }
        }
    }
}


